package bytes;

import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

/**
 * @Description
 * @Author zhaobaolin
 * @Date 2018/11/11
 */
public class BufferedInputStreamExample {
    public static void main(String[] args) {
        demo();
    }

    private static void demo()
    {
        String s = "1234567890";
        byte[] buf = s.getBytes();
        ByteArrayInputStream in = new ByteArrayInputStream(buf);
        try(BufferedInputStream f = new BufferedInputStream(in)){
            int c = f.available();
            int limit = 4;
            for(int i=0;i<c;i++){
                int r = f.read();
                if(i == limit){
                    f.mark(limit);
                }
                System.out.print((char) r);//输出1234567890
            }
            System.out.println();
            f.reset();
            for(int i=0;i<c-(limit+1);i++){
                int r = f.read();
                System.out.print((char) r);//输出67890
            }
        }catch (IOException e){
            e.printStackTrace();
        }
    }
}
